﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using Microsoft.Phone.Tasks;
using SverigesRadio.SverigesRadioApp.WindowsPhoneApplication.Commands;
using SverigesRadio.SverigesRadioApp.WindowsPhoneApplication.ViewModels.Channels;

namespace SverigesRadio.SverigesRadioApp.WindowsPhoneApplication.ViewModels
{
    public class DirektControlViewModel : IPivotViewModel
    {
        public MainPageViewModel ParentPageViewModel { get; private set; }

        public DirektControlViewModel(MainPageViewModel parentPageViewModel)
        {
            ParentPageViewModel = parentPageViewModel;
        }

        private ChannelInformationViewModel selectedChannel;
        public ChannelInformationViewModel SelectedChannel
        {
            get { return selectedChannel; }
            set { selectedChannel = value; }
        }

        private ChannelInformationViewModel channelSelection;

        public ChannelInformationViewModel ChannelSelection
        {
            get { return channelSelection; }
            set
            {
                channelSelection = value;
                SelectedChannel = value;

            }
        }

        public ICommand SelectionChangedCommand
        {
            get { return new Command(null, SelectionChanged); }
        }

        public ICommand VisitHomePageCommand
        {
            get { return new Command(null, p => VisitHomePage()); }
        }

        private void VisitHomePage()
        {
            WebBrowserTask webTask = new WebBrowserTask {Uri = new Uri(SelectedChannel.ProgramUrl)};
            webTask.Show();
        }

        private void SelectionChanged(object args)
        {
            channelSelection = null;
 
            //ParentPageViewModel.PlayerViewModel.IsStreamedTrack = true;
            //ParentPageViewModel.PlayerViewModel.SelectedAudioTrack = SelectedChannel.ToAudioTrack();

            //ParentViewModel.NavigationService.NavigateTo(ViewType.Player);

        }

        public ICommand PlayDirectCommand
        {
            get { return new Command(null, p => PlayDirect()); }
        }

        private void PlayDirect()
        {


        }


        public void IndexChanged()
        {
            
        }

        public void Navigated(IDictionary<string, string> queryString)
        {
            
        }
    }
}
